package com.wangxinyuchuan.demo.builder;

/**
 * @author wangxinyuchuan
 * @date 2023/4/16 12:41 PM
 */
public abstract class Builder {

    private boolean initialized = false;

    public void makeTitle(String title) {
        if (!initialized) {
            buildTitle(title);
            initialized = true;
        }
    }

    public void makeString(String str) {
        if (initialized) {
            buildString(str);
        } else {
            throw new UnsupportedOperationException("Please apply makeTitle first");
        }
    }

    public void makeItems(String[] items) {
        if (initialized) {
            buildItems(items);
        } else {
            throw new UnsupportedOperationException("Please apply makeTitle first");
        }
    }

    public void close() {
        if (initialized) {
            buildDone();
        } else {
            throw new UnsupportedOperationException("Please apply makeTitle first");
        }
    }

    protected abstract void buildTitle(String title);
    protected abstract void buildString(String str);
    protected abstract void buildItems(String[] items);
    protected abstract void buildDone();
}
